package com.atguigu.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.yygh.cmn.service.DictService;
import com.atguigu.yygh.common.exceptionhandle.YyghException;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

public class DictListListener extends AnalysisEventListener<DictEeVo> {

    private DictService dictService;

    public DictListListener(DictService dictService){
        this.dictService = dictService;
    }

    // 读取数据 一行一行读取
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        if(dictEeVo == null){
            throw new YyghException("数据为空",20001);
        }
        // 调用方法来添加到数据
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo,dict);
        dictService.save(dict);

    }

    // 读取之后的操作
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
